import Vue from 'vue'
import Vuex from 'vuex'
import { request } from '@/utils/wx'
import { apiDomain } from '@/utils/constant'

Vue.use(Vuex)

const API = {
  /** 获取openId，POST */
  wechatAuth: `${apiDomain}/api/player/login`,
  /** 更新玩家的信息，POST */
  updatePlayerInfo: `${apiDomain}/api/player/info`,
  /** 更新玩家的信息，GET */
  getPlayerInfo: `${apiDomain}/api/player/info`,
  /** 通过playerid获取玩家的个人信息和店铺信息，GET */
  getPlayerStoreInfo: `${apiDomain}/api/player/store`,
  /** 获取评论店铺，GET */
  storeComment: `${apiDomain}/api/store/comment`,
  /** 评论店铺，POST */
  doStoreComment: `${apiDomain}/api/store/comment`,
  /** 删除评论，POST */
  delStoreComment: `${apiDomain}/api/store/delcomment`,
  /** 评论点赞，POST */
  likeStoreComment: `${apiDomain}/api/store/likecomment`,
  /** 获取鲜花记录，GET */
  flowerRecord: `${apiDomain}/api/player/flowerRecord`,
  /** 店铺装扮，POST */
  storeDressup: `${apiDomain}/api/store/dressup`,
  /** 更新玩家的联系方式，POST */
  updatePlayerContact: `${apiDomain}/api/player/contact`,
  /** 获取玩家的联系方式，GET */
  getPlayerContact: `${apiDomain}/api/player/contact`,
  /** 获取商品类目，GET */
  getStoreItemCate: `${apiDomain}/api/store/itemcate`,
  /** 获取店铺商品，GET */
  getStoreItem: `${apiDomain}/api/store/item`,
  /** 店铺上架商品，POST */
  upStoreItem: `${apiDomain}/api/store/itemup`,
  /** 获取已上架的商品，GET */
  getUpStoreItem: `${apiDomain}/api/store/itemup`,
  /** 解锁货架，POST */
  unLockItems: `${apiDomain}/api/store/unlockitems`,
  /** 获取礼品列表，GET */
  getGift: `${apiDomain}/api/gift`,
  /** 礼品兑换，POST */
  exchangeGift: `${apiDomain}/api/gift/exchange`,
  /** 排行榜-全国榜，GET */
  allRank: `${apiDomain}/api/statistic/allRank`,
  /** 排行榜-好友榜，GET */
  friendRank: `${apiDomain}/api/statistic/friendRank`,
  /** 签到的规则，GET */
  signRule: `${apiDomain}/api/sgin/rule`,
  /** 签到，GET */
  sign: `${apiDomain}/api/sgin`,
  /** 签到记录，GET */
  signRecord: `${apiDomain}/api/sgin/record`,
  /** 近7日鲜花汇总，GET */
  last7Statistic: `${apiDomain}/api/statistic/last7`,
  /** 近7天统计数据，GET */
  reportStatistic: `${apiDomain}/api/statistic/report`,
  /** 获取玩家下级的收益列表，GET */
  childrenFlowers: `${apiDomain}/api/player/childrenFlowers`,
  /** 收取下级合伙人的收益，GET */
  reapChildrenFlowers: `${apiDomain}/api/player/reapChildrenFlowers`,
  /** 参与抽奖，GET */
  joinLuckyDraw: `${apiDomain}/api/player/luckydraw`,
  /** 帮其他店铺驱逐猴子，POST */
  driveMonkey: `${apiDomain}/api/player/driveMonke`,
  /** 广告接口，GET */
  advertise: `${apiDomain}/api/advertise`,
  /** 玩家点赞，POST */
  playerLike: `${apiDomain}/api/player/like`,
  /** 鲜花总数，GET */
  allflower: `${apiDomain}/api/config/allflower`,
  /** 兑换列表，GET */
  exchangeList: `${apiDomain}/api/gift/exchangeList`,
}

const store = new Vuex.Store({
  state: {},
  mutations: {},
  actions: {
    // 获取openid
    async wechatAuth ({ state }, code) {
      const res = await request({
        method: 'POST',
        url: API.wechatAuth,
        data: { code },
      })
      return res.result
    },
    // 更新玩家的信息
    async updatePlayerInfo ({ state }, data) {
      const res = await request({
        method: 'POST',
        url: API.updatePlayerInfo,
        data
      })
      return res.result
    },
    // 获取玩家的信息
    async getPlayerInfo ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.getPlayerInfo,
        data
      })
      return res.result
    },
    // 通过playerid获取玩家的个人信息和店铺信息
    async getPlayerStoreInfo ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.getPlayerStoreInfo,
        data
      })
      return res.result
    },
    // 获取评论店铺
    async getStoreComment ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.storeComment,
        data
      })
      return res.result
    },
    // 评论店铺
    async doStoreComment ({ state }, data) {
      const res = await request({
        method: 'POST',
        url: API.doStoreComment,
        data
      })
      return res.result
    },
    // 删除评论
    async delStoreComment ({ state }, data) {
      const res = await request({
        method: 'POST',
        url: API.delStoreComment,
        data
      })
      return res.result
    },
    // 点赞评论
    async likeStoreComment ({ state }, data) {
      const res = await request({
        method: 'POST',
        url: API.likeStoreComment,
        data
      })
      return res.result
    },
    // 获取鲜花记录
    async getFlowerRecord ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.flowerRecord,
        data
      })
      return res.result
    },
    // 装扮店铺
    async storeDressup ({ state }, data) {
      const res = await request({
        method: 'POST',
        url: API.storeDressup,
        data
      })
      return res.result
    },
    // 更新玩家的联系方式
    async updatePlayerContact ({ state }, data) {
      const res = await request({
        method: 'POST',
        url: API.updatePlayerContact,
        data
      })
      return res.result
    },
    // 获取玩家的联系方式
    async getPlayerContact ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.getPlayerContact,
        data
      })
      return res.result
    },
    // 获取商品类目
    async getStoreItemCate ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.getStoreItemCate,
        data
      })
      return res.result
    },
    // 获取店铺商品
    async getStoreItem ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.getStoreItem,
        data
      })
      return res.result
    },
    // 店铺上架商品
    async upStoreItem ({ state }, data) {
      const res = await request({
        method: 'POST',
        url: API.upStoreItem,
        data
      })
      return res.result
    },
    // 获取已上架商品
    async getUpStoreItem ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.getUpStoreItem,
        data
      })
      return res.result
    },
    // 解锁货架
    async unLockItems ({ state }, data) {
      const res = await request({
        method: 'POST',
        url: API.unLockItems,
        data
      })
      return res.result
    },
    // 获取礼品列表
    async getGift ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.getGift,
        data
      })
      return res.result
    },
    // 礼品兑换
    async exchangeGift ({ state }, data) {
      const res = await request({
        method: 'POST',
        url: API.exchangeGift,
        data
      })
      return res.result
    },
    // 排行榜-全国榜
    async getAllRank ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.allRank,
        data
      })
      return res.result
    },
    // 排行榜-好友榜
    async getFriendRank ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.friendRank,
        data
      })
      return res.result
    },
    // 签到规则
    async getSignRule ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.signRule,
        data
      })
      return res.result
    },
    // 签到
    async doSign ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.sign,
        data
      })
      return res.result
    },
    // 签到记录
    async getSignRecord ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.signRecord,
        data
      })
      return res.result
    },
    // 近7日鲜花汇总
    async getLast7Statistic ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.last7Statistic,
        data
      })
      return res.result
    },
    // 近7日统计数据
    async getReportStatistic ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.reportStatistic,
        data
      })
      return res.result
    },
    // 获取玩家下级的收益列表
    async getChildrenFlowers ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.childrenFlowers,
        data
      })
      return res.result
    },
    // 收取下级合伙人的收益
    async reapChildrenFlowers ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.reapChildrenFlowers,
        data
      })
      return res.result
    },
    // 参与抽奖
    async joinLuckyDraw ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.joinLuckyDraw,
        data
      })
      return res.result
    },
    // 驱赶猴子
    async driveMonkey ({ state }, data) {
      const res = await request({
        method: 'POST',
        url: API.driveMonkey,
        data
      })
      return res.result
    },
    // 广告
    async getAdvertise ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.advertise,
        data
      })
      return res.result
    },
    // 玩家点赞
    async doPlayerLike ({ state }, data) {
      const res = await request({
        method: 'POST',
        url: API.playerLike,
        data
      })
      return res.result
    },
    // 获取鲜花数量
    async getAllflower ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.allflower,
        data
      })
      return res.result
    },
    // 获取兑换列表
    async getExchangeList ({ state }, data) {
      const res = await request({
        method: 'GET',
        url: API.exchangeList,
        data
      })
      return res.result
    },
  }
})

export default store
